package cn.tangwei.user.controller;

import cn.tangwei.basic.exception.BusinessException;
import cn.tangwei.basic.utils.AjaxRusult;
import cn.tangwei.user.service.IVerifyCodeSercive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 发送验证码的接口
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeSercive verifyCodeSercive;

    /**
     * 前端串入的参数很少的情况，可以用Map接收对象
     * @param map
     * @return
     */
    @PostMapping("/sSmsCode")
    public AjaxRusult sSmsCode(@RequestBody Map<String, String> map){
        try {
//            String phone = map.get("phone");
//            String type = map.get("type");
            // System.out.println(phone);
            verifyCodeSercive.sSmsCode(map);
            return AjaxRusult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage( e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage("系统繁忙，稍后重试");
        }

    }
}
